package edu.cmu.cs211.proximitycounter.tests;

import edu.cmu.cs211.proximitycounter.tests.TestUtil;
import edu.cmu.cs211.proximitycounter.counter.*;

import static org.junit.Assert.*;
import java.util.Random;
import org.junit.Test;

public class CountTest {

	@Test 
	public void sweepTest()
	{
		// simple test
		int n = 5, r = 2;
		MyTreeSet<Point> s = new MyTreeSet<Point>();
		Point[] a = new Point[n];
		
		a[0] = new Point(0,0);
		a[1] = new Point(1,1);
		a[2] = new Point(2,2);
		a[3] = new Point(3,3);
		a[4] = new Point(4,7);
		Count c = new Count(a);
		assertEquals(TestUtil.bruteForce(r, a),c.countPairs(r));
		
		// loop test to test the speed
		for(int z = 0; z < 100; z++)
		{
			n = 1000; r = 100;
			s = new MyTreeSet<Point>();
			a = new Point[n];
			Random rand = new Random(37);
			while (s.size() < n) {
				s = s.insert(new Point(rand.nextInt(1000), rand.nextInt(1000)));
			}
			int i = 0;
			for (Point p: s) a[i++] = p;
			c = new Count(a);
			assertEquals(c.countPairs(r), TestUtil.bruteForce(r, a));
			
			r = 10;
			MyTreeSet<Point> set = new MyTreeSet<Point>();
			Point[] array = new Point[n];
			rand = new Random(37);
			while (set.size() < n) {
				set = set.insert(new Point(rand.nextInt(1000), rand.nextInt(1000)));
			}
			int j = 0;
			for (Point p: set) array[j++] = p;
			Count co = new Count(array);
			assertEquals(co.countPairs(r), TestUtil.bruteForce(r, array));
		}
		
	}

}